package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.BackstageArticleAddDTO;
import com.sky.dto.BackstageArticleQueryDTO;
import com.sky.dto.BackstageArticleUpdateDTO;
import com.sky.mapper.BackstageArticleMapper;
import com.sky.result.PageResult;
import com.sky.service.BackstageArticleService;
import com.sky.vo.AnnouncementsVO;
import com.sky.vo.ArticleInfoVO;
import com.sky.vo.BackstageArticleSearchVO;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@Service
public class BackstageArticleServiceImp implements BackstageArticleService {
    @Autowired
    private BackstageArticleMapper backstageArticleMapper;

    @Override
    public PageResult getAllArticle(BackstageArticleQueryDTO backstageArticleQueryDTO) {
        PageHelper.startPage(backstageArticleQueryDTO.getPage(), backstageArticleQueryDTO.getPageSize());
        Page<AnnouncementsVO> articleList = backstageArticleMapper.getArticleList(backstageArticleQueryDTO);
        long total = articleList.getTotal();
        List records = articleList.getResult();
        return new PageResult(total,records);
    }

    @Override
    public ArticleInfoVO getArticleById(Integer id) {
        return backstageArticleMapper.getArticleById(id);
    }

    @Override
    public void updateArticle(BackstageArticleUpdateDTO backstageArticleUpdateDTO) {
        backstageArticleMapper.updateArticle(backstageArticleUpdateDTO);
    }

    @Override
    public void addArticle(BackstageArticleAddDTO backstageArticleAddDTO) {
        backstageArticleMapper.addArticle(backstageArticleAddDTO);
    }

    @Override
    public void deleteArticle(List<Integer> ids) {
        backstageArticleMapper.deleteArticle(ids);
    }

    @Override
    public String getArticleByTitle(Integer id) {
        String article = backstageArticleMapper.getArticleByTitle(id);
        return article;
    }

    @Override
    public List<BackstageArticleSearchVO> getArticleByContent(String title) {
        return backstageArticleMapper.getArticleByContent(title);
    }
    // @Override
    // public List<ArticleInfoVO> getAllArticle() {
    //     List<ArticleInfoVO> articleInfoList = backstageArticleMapper.getArticleList();
    //     return articleInfoList;
    // }
}
